#!/bin/sh

if [ -z $1 ];then
   hive_db=default
else
   hive_db=$1
fi

if [ -z $2 ];then
   create_time=`date  "+%Y-%m-%d %H-%M-%S"`
else
   create_time=$2
fi

hiveconfig=$(cat <<"EOF" /home/hdfs/parquet_shell/hive_parquet_scripts/hive.config
EOF
)

sql_suffix=$(cat <<EOF 
INSERT INTO TABLE ${hive_db}.navinfo_parquet_0f37 PARTITION (part_time, hashtid) SELECT tid, gpstime, latitude, longitude, height, engineoutputtorque, speed, accelerator, brake, rotation, gear, clutchswitch, realtimeoilconsumption, fuelconsumptionrate, version, retransmissionpackets, serialnumber, receivedate, originallat, originallng, protocoltype, vehiclespeed, barometricpressure, frictiontorque, scrupstreamnoxsensoroutput, scrdownstreamnoxsensoroutput, reagentallowance, airinflow, scrinlettemperature, scroutlettemperature, dpfdropoutvoltage, enginecoolanttemperature, tanklevel, positioningstate, mileage, rvalue, svalue, commandunit, vin, terminalversion, encryption, rlength, slength, enginebrakingstate, exhaustbrakingstate, emptysignal, exhaustflow, fanspeed, mechanicalboxgear, instrumentspeed, wheelspeed, parkingbrakeswitch, cruisecontrolsettingswitch, targetgear, slope, load, fuellevel, watertemperature, atmosphericpressure, intakeairtemperature, atmospherictemperature, exhaustgastemperature, intakemanifoldboostpressure, relativepressure, enginetorquemode, oilpressure, urealevel, statusflag, brakerate, gpsdirection, airconditionstatus, transmissionrotation,auxiliarybrakehandlestatus,ureaInjection,totalureaInjection,ureaInjectionSignal,ureaPumpPressureSignal,avgGasConsumption, '${create_time}', part_time, hashtid FROM ${hive_db}.navinfo_stage_0f37 distribute by part_time, hashtid ;
EOF
)

sql="${hiveconfig}${sql_suffix}"
############  execute begin   ###########
hive --hiveconf "tez.queue.name=hive" -S -e "$sql"
#echo $sql
